Use case: DCMI snapshot capture

Capture a single frame using hardware synchronization. The application receives one frame callback.

Sequence diagram

Snapshot capture using HAL1 DCMI + DMA APIs.

  @startuml
  hide footbox
  participant "User Application" as app
  participant "DCMI Driver" as dcmi
  participant "DMA Driver" as dma

  group Initialization + Configuration
     app->dcmi : HAL_DCMI_Init()
     dcmi-->app : HAL_OK
     app->dcmi : __HAL_LINKDMA()
     note right: link DMA handle to DCMI handle
  end

  group Snapshot
     app->dcmi : HAL_DCMI_Start_DMA()
     dcmi-->app : HAL_OK
     dma->dcmi : DMA transfer complete
     dcmi->app : HAL_DCMI_FrameEventCallback()
  end
  group De-initialization
     app->dcmi : HAL_DCMI_DeInit()
     dcmi-->app : HAL_OK
  end
  @enduml

Code snippet

HAL1

HAL2

DCMI_HandleTypeDef hdcmi;
DMA_HandleTypeDef hdma;


uint32_t *buf = (uint32_t*)0x24000000U;
uint32_t words = 640U * 480U * 2U / 4U;

hdcmi.Instance              = DCMI;


hdcmi.Init.JPEGMode         = DCMI_JPEG_DISABLE;
hdcmi.Init.PCKPolarity      = DCMI_PCKPOLARITY_RISING;
hdcmi.Init.HSPolarity       = DCMI_HSPOLARITY_HIGH;
hdcmi.Init.VSPolarity       = DCMI_VSPOLARITY_HIGH;
hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;


hdcmi.Init.SynchroMode      = DCMI_SYNCHRO_HARDWARE;

hdcmi.Init.CaptureRate      = DCMI_CR_ALL_FRAME;

hdcmi.Init.ByteSelectMode   = DCMI_BSM_ALL;
hdcmi.Init.ByteSelectStart  = DCMI_OEBS_ODD;
hdcmi.Init.LineSelectMode   = DCMI_LSM_ALL;
hdcmi.Init.LineSelectStart  = DCMI_OELS_ODD;
HAL_DCMI_Init(&hdcmi);
__HAL_LINKDMA(&hdcmi, DMA_Handle, hdma);

HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, buf, words);

void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
{
}
HAL_DCMI_DeInit(&hdcmi);
hal_dcmi_handle_t hdcmi;
hal_dma_handle_t hdma;
hal_dcmi_parallel_config_t cfg;
hal_dcmi_pipe_config_t pipe;
uint32_t *buf = (uint32_t*)0x24000000U;
uint32_t len = 640U * 480U * 2U;

HAL_DCMI_Init(&hdcmi, HAL_DCMI);
HAL_DCMI_SetDMA(&hdcmi, &hdma);

cfg.format = HAL_DCMI_FORMAT_UNCOMPRESSED;
cfg.pixel_polarity = HAL_DCMI_PIXEL_CLOCK_RISING;
cfg.hsync_polarity = HAL_DCMI_HSYNC_HIGH;
cfg.vsync_polarity = HAL_DCMI_VSYNC_HIGH;
cfg.data_width = HAL_DCMI_EXTENDED_DATA_8_BITS;
HAL_DCMI_PARALLEL_SetConfig(&hdcmi, &cfg);

/* Synchro mode is set to HARDWARE by default */

pipe.frame_rate = HAL_DCMI_FRAME_CAPTURE_ALL;
HAL_DCMI_SetConfigPipe(&hdcmi, HAL_DCMI_PIPE_0, &pipe);






HAL_DCMI_StartPipe_DMA(&hdcmi, HAL_DCMI_PIPE_0, HAL_DCMI_CAPTURE_SNAPSHOT, buf, len);

void HAL_DCMI_PipeFrameEventCallback(hal_dcmi_handle_t *hdcmi, hal_dcmi_pipe_t pipe)
{
}
HAL_DCMI_DeInit(&hdcmi);

Key changes

  1. HAL2 introduces pipeline-based capture through HAL_DCMI_StartPipe_DMA().

  2. HAL2 separates DMA association and configuration using HAL_DCMI_SetDMA(), HAL_DCMI_PARALLEL_SetConfig(), and HAL_DCMI_SetConfigPipe().

  3. Frame callback becomes pipe-specific with HAL_DCMI_PipeFrameEventCallback().